package cn.yc.reader;

import java.io.*;

public class ObjectInputStream_ {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 指定反序列化的文件
        String filePath = "e:\\io\\ioObject_Output_Stream.bat";
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filePath));

        // 注意：反序列化的顺序要和当初序列化的顺序相同
        System.out.println(ois.readInt());
        System.out.println(ois.readBoolean());
        System.out.println(ois.readChar());
        System.out.println(ois.readDouble());
        System.out.println(ois.readUTF());
        Object dog = ois.readObject();
        System.out.println("运行类型 = "+dog.getClass());
        System.out.println("dog信息 = "+dog);

        //如果需要调用Dog的方法，需要向下转型
        Dog dog1  = (Dog) dog;
        System.out.println("dog1信息："+dog1.getName());
        // 关闭流，关闭外层流
        ois.close();
    }
}


